package com.atguigu.lease;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

//定义一个定时类写一些定时方法
//要加入核心容器
@Component
public class MyTasks {

    //注入service
    @Autowired
    private LeaseAgreementService agreementService;

    //定义定时方法
    //cron单位 *秒 *分 *时 *日 *月 *周
    @Scheduled(cron = "0/10 * * * * *")
    public void checkLeaseStatus(){

        //定义一个修改可以装值的lambda
        LambdaUpdateWrapper<LeaseAgreement> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        //修改(2,5,7)状态
        lambdaUpdateWrapper.in(LeaseAgreement::getStatus, LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING,LeaseStatus.RENEWING);
        //小于哪些时间
        lambdaUpdateWrapper.lt(LeaseAgreement::getLeaseEndDate, new Date());
        //到规定时间修改状态为'4'
        lambdaUpdateWrapper.set(LeaseAgreement::getStatus,LeaseStatus.EXPIRED);
        //修改service层
        agreementService.update(lambdaUpdateWrapper);
    }
}
